//
//  SYMomentsTabelViewController.m
//  BShouGongKe
//
//  Created by 曹雁彬 on 15/8/10.
//  Copyright (c) 2015年 L750. All rights reserved.
//

#import "SYMomentsTableViewController.h"
#import "Header.h"

@interface SYMomentsTableViewController ()
@property (nonatomic,strong)UIScrollView *tagSV;
@property (nonatomic,strong)NSMutableArray *tagArr;
@property (nonatomic,assign)CGFloat tagLenth;
@property (nonatomic,strong)NSMutableArray *tagLengthArr;
@end

@implementation SYMomentsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor cyanColor];
    self.navigationItem.title = @"时 刻";
    _tagArr = [[NSMutableArray alloc]initWithCapacity:0];
    _tagLengthArr = [[NSMutableArray alloc]initWithCapacity:0];
    [_tagArr addObject:@"手工客官方"];
    [_tagArr addObject:@"adasdasdasdsad"];
    [_tagArr addObject:@"adasdas"];
    [_tagArr addObject:@"ad"];
    _tagSV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 40, 40)];
    
    
    
    [self heightForTag];
    _tagSV.contentSize = CGSizeMake(_tagLenth, 40);
    _tagSV.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview:_tagSV];
    
    
}


- (void)heightForTag{
    for (int i = 0; i < _tagArr.count; i++) {
        NSString *tag = _tagArr[i];
        CGFloat width = [tag boundingRectWithSize:CGSizeMake(0, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18] forKey:NSAttachmentAttributeName] context:nil].size.width;
        UIButton *tagButton = [UIButton buttonWithType:UIButtonTypeCustom];
        tagButton.frame = CGRectMake(_tagLenth + 10, 0, width, 40);
        [tagButton setTitle:tag forState:UIControlStateNormal];
        tagButton.tag = 1000 + i;
        [tagButton addTarget:self action:@selector(changeMoments:) forControlEvents:UIControlEventTouchUpInside];
        [_tagSV addSubview:tagButton];
        _tagLenth += width;
        [_tagLengthArr addObject:@(width)];
    }
}


- (void)changeMoments:(UIButton *)sender{
    if (sender.frame.origin.x > SCREEN_WIDTH / 2) {
        _tagSV.contentOffset = CGPointMake(SCREEN_WIDTH / 2 - sender.frame.origin.x, 0);
        NSLog(@"%f",SCREEN_WIDTH / 2 - sender.frame.origin.x);
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
